<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	  <pre id="box"></pre>
	  <pre id="box2"></pre>
	  <script>
	    function getLocation(){
          if (navigator.geolocation)
          {
            console.log("进来")
              //获取当前地理位置
              navigator.geolocation.getCurrentPosition(function(position){
                let json = {};
                for( let key in  position.coords){
                  json[key] = position.coords[key];
                }
                box.innerHTML = JSON.stringify(json,null,4)
                console.log(JSON.stringify(json,null,4))
              });
              //实时监控上传位置
              let watchID = navigator.geolocation.watchPosition(function(position) {
                 let json = {};
                for( let key in  position.coords){
                  json[key] = position.coords[key];
                }
                box2.innerHTML = JSON.stringify(json,null,4)
              });
              //clearWatch(watchID);
          }
          else
          {
              box.innerHTML="该浏览器不支持获取地理位置。";
          }
      }
      getLocation()
	    
	  </script>
	</body>
</html>
